package com.turing.manage.manager;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import java.util.Map;

import com.turing.dao.Dao;
import com.turing.dao.DaoImpl;

public class ManagerService {
	
	Dao dao = new DaoImpl();
	
	public List<Map<String, Object>> queryManagerAll() throws ClassNotFoundException, SQLException {
		return dao.executeQueryForList("select * from manager");
	}

	public void save(String manager_name, String manager_pass, String virtulpath) throws ClassNotFoundException, FileNotFoundException, SQLException, IOException {
		
		String sql=" insert into manager values(0,?,?,?)  ";
		int [] types=new int[3];
		types[0]=Types.VARCHAR;
		types[1]=Types.VARCHAR;
		types[2]=Types.VARCHAR;
		
		
		Object []values=new Object[3];
		values[0]=manager_name;
		values[1]=manager_pass;
		values[2]=virtulpath;
		dao.executeUpdate(sql, types, values);
	}

	public Map<String, Object> querymanagerById(String id) throws ClassNotFoundException, SQLException {
		return dao.executeQueryForMap("select * from manager where manager_id='"+id+"'");
	}

	public void updateStudent(String manager_id, String manager_name, String manager_pass, String fileSaveName) throws ClassNotFoundException, SQLException {
		dao.executeUpdate("update manager set manager_name='"+manager_name+"',manager_pass='"+manager_pass+"',manager_imgpath='"+fileSaveName+"' where manager_id='"+manager_id+"'");
	}

	public void deleteByld(String id) throws ClassNotFoundException, SQLException {
		dao.executeUpdate("delete from manager where manager_id='"+id+"'");
	}

}
